package icu.bughub.app.app.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Divider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.google.accompanist.placeholder.PlaceholderHighlight
import com.google.accompanist.placeholder.material.shimmer
import com.google.accompanist.placeholder.placeholder
import icu.bughub.app.app.model.entity.ArticleEntity

/**
 * 文章列表
 */
@Composable
fun ArticleItem(
    article: ArticleEntity,
    articleLoadSuccess: Boolean = false,
    modifier: Modifier = Modifier
) {
    Column(
        modifier = modifier
            .padding(horizontal = 8.dp, vertical = 4.dp)
            .clip(RoundedCornerShape(8.dp))
            .background(Color(0xffffffff))
            .placeholder(
                visible = !articleLoadSuccess,
                color = Color.LightGray.copy(alpha = 0.5f),
                highlight = PlaceholderHighlight.shimmer()
            )
            .then(Modifier.padding(horizontal = 8.dp))
    ) {

        Text(
            text = article.title ?: "",
            fontSize = 16.sp,
            maxLines = 2,
            overflow = TextOverflow.Ellipsis,
            color = Color(0xFF333333),
            modifier = Modifier
                .padding(bottom = 8.dp, top = 8.dp)
                .placeholder(
                    visible = !articleLoadSuccess,
                    color = Color.LightGray.copy(alpha = 0.5f),
                    highlight = PlaceholderHighlight.shimmer()
                ),
        )

        Row(
            modifier = Modifier
                .padding(vertical = 8.dp)
                .fillMaxWidth(),
            horizontalArrangement = Arrangement.SpaceBetween
        ) {
            Text(
                text = "${article.source}      ${article.timestamp}",
                fontSize = 10.sp,
                maxLines = 1,
                overflow = TextOverflow.Ellipsis,
                color = Color(0xFF666666)
            )
        }

        Spacer(Modifier.height(8.dp))
        Divider(color = Color(0x66E5E5E5), thickness = 0.5.dp)
    }
}